/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.XPath;

namespace DaveSexton.DocProject.Sandcastle.TopicManagement
{
	internal sealed class XmlTopicComparer : IEqualityComparer<IXPathNavigable>
	{
		#region Public Properties
		public static readonly XmlTopicComparer Default = new XmlTopicComparer();
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="XPathNavigatorComparer" /> class for the <see cref="Default"/> singleton.
		/// </summary>
		private XmlTopicComparer()
		{
		}
		#endregion

		#region IEqualityComparer<XmlTopicComparer> Members
		public bool Equals(IXPathNavigable x, IXPathNavigable y)
		{
			return (x == null || y == null)
				? x == null && y == null
				: x.CreateNavigator().IsSamePosition(y.CreateNavigator())
						|| string.Equals(x.CreateNavigator().GetAttribute("id", ""), y.CreateNavigator().GetAttribute("id", ""), StringComparison.Ordinal);
		}

		public int GetHashCode(IXPathNavigable obj)
		{
			return ((obj == null) ? "" : obj.CreateNavigator().GetAttribute("id", "")).GetHashCode();
		}
		#endregion
	}
}
